package com.ruoyi.web.controller.vote;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.score.domain.HouseVoteScore;
import com.ruoyi.score.service.IHouseVoteScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 投票结果Controller
 * 
 * @author ruoyi
 * @date 2023-10-07
 */
@RestController
@RequestMapping("/vote/score")
public class HouseVoteScoreController extends BaseController
{
    @Autowired
    private IHouseVoteScoreService houseVoteScoreService;

    /**
     * 查询投票结果列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseVoteScore houseVoteScore)
    {
        startPage();
        List<HouseVoteScore> list = houseVoteScoreService.selectHouseVoteScoreList(houseVoteScore);
        return getDataTable(list);
    }

    /**
     * 导出投票结果列表
     */
    @Log(title = "投票结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseVoteScore houseVoteScore)
    {
        List<HouseVoteScore> list = houseVoteScoreService.selectHouseVoteScoreList(houseVoteScore);
        ExcelUtil<HouseVoteScore> util = new ExcelUtil<HouseVoteScore>(HouseVoteScore.class);
        util.exportExcel(response, list, "投票结果数据");
    }

    /**
     * 获取投票结果详细信息
     */
    @GetMapping(value = "/{scoreId}")
    public AjaxResult getInfo(@PathVariable("scoreId") Long scoreId)
    {
        return AjaxResult.success(houseVoteScoreService.selectHouseVoteScoreByScoreId(scoreId));
    }

    /**
     * 新增投票结果
     */
    @Log(title = "投票结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseVoteScore houseVoteScore)
    {
        return toAjax(houseVoteScoreService.insertHouseVoteScore(houseVoteScore));
    }

    /**
     * 修改投票结果
     */
    @Log(title = "投票结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseVoteScore houseVoteScore)
    {
        return toAjax(houseVoteScoreService.updateHouseVoteScore(houseVoteScore));
    }

    /**
     * 删除投票结果
     */
    @Log(title = "投票结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scoreIds}")
    public AjaxResult remove(@PathVariable Long[] scoreIds)
    {
        return toAjax(houseVoteScoreService.deleteHouseVoteScoreByScoreIds(scoreIds));
    }
}
